#include "Cow.h"
#include "EcoSystem.h"
#include <iostream>
Cow::Cow(EcoSystem *eco_system) :
Consumer(eco_system)
{
    set_alive();
    set_max_hp(1000);
    set_hp(800);
    set_init_speed(0.5);
    set_speed(0.5);
    set_life_span(LIFE_SPAN[get_species_id()] * (1 + max(min(0.2, EcoSystem::random_double() - 0.5), -0.2)));
}

Cow::~Cow() {}

inline const unsigned int Cow::get_species_id() const
{
    return COW_SPECIES_ID;
}

Gdiplus::Image *Cow::get_entity_image() const
{
    static Gdiplus::Image *img = Gdiplus::Image::FromFile(L".\\images\\cow.png");
    return img;
}

Entity *Cow::new_entity() const
{
    return new Cow(eco_system);
}


void Cow::on_tick()
{
    set_age(get_age() + 1);
    natural_growth();
    multiply();
    //std::cout << get_max_hp() << " " << get_init_speed() << std::endl;
    set_hp(get_hp() - get_speed() * get_speed() / 2);
    
    double factor = get_environment_factor();
    if (!avoid_predator(2.0*get_init_speed()*factor))
        if (!prey(get_init_speed()*1.5*factor))
            random_motion(get_init_speed()*1.2*factor);
}

int    Cow::get_cost_of_being_preyed() const
{
    return 500;
}
int    Cow::get_gain_after_being_preyed() const
{
    return 0.25*get_hp();
}